<% content_for :head do %>
  <%= javascript_include_tag "graphing" %>
<% end %>

<% if @agent.memory[:data] && @agent.memory[:data].length > 0 %>
  <h3>最新趋势</h3>
  <% @agent.memory[:data].each.with_index do |(group_name, data), index| %>
    <div class="filter-group counts">
      <div class='filter'><%= link_to group_name.to_s, "https://twitter.com/search?q=#{CGI::escape group_name.to_s}", :target => "blank" %></div>

      <div class="chart-container group-<%= index.to_s %>">
        <div class="y-axis"></div>
        <div class="chart"></div>
        <div class="timeline"></div>
      </div>

      <script>
        $(function() {
          var $chart = $(".chart-container.group-<%= index.to_s %>").last();
          var data = <%= Utils.jsonify(data.select {|c, _t| !c.nil? }.map {|count, time| { :x => time.to_i, :y => count.to_f } }) %>;
          var peaks = <%= Utils.jsonify((@agent.memory[:peaks] && @agent.memory[:peaks][group_name]) || []) %>;
          var name = <%= Utils.jsonify(group_name) %>;

          renderGraph($chart, data, peaks, name);
        });
      </script>
    </div>
  <% end %>
<% else %>
  <p>
  没有收到任何数据.
  </p>
<% end %>
